#include "task_app_logic.h"

static TaskHandle_t thread_app_dazzling;
app_status_info_t app_dazzling_status;

u8 app_logic_init()
{
    app_logic_set_ssp(SSP_LOGO); //让设备进入开机动画模式
    app_logic_set_last_ssp(NUM_SYS_SSP); //将初始化化模式设置为上电模式
    /*    
    UV_about_dazzling_recover();
    micro_about_dazzling_recover();
    scene_dazzling_recover();
    light_len_dazzling_recover();
    custom_ssp_dazzling_recover();
    part_dazzling_recover();
    brighness_dazzling_recover();
    */
    //memset(&app_dazzling_status,0,sizeof(app_status_info_t));
    set_light_length(50); //初始化100个灯珠
    init_brighness_level(10); //初始化一半的亮度
    return 1;
}

void app_logic_general_handle(SYS_OPT_KEY opt)
{
    mode_net_handle(opt);
    mode_handle(opt);
}

void app_logic_loop(void *pvParameters)
{
    key_act_param key_act; 
    SYS_OPT_KEY opt;
    app_logic_init(); //初始化状态逻辑
    while(1)
    {
        opt.oepation = OPT_NONE;
        if(xQueueReceive(sensor_dect_queue,&key_act,0)) //获取按键状态
        {
            LOG_INFO("app logic task : recv msg,type is %d,key num is %d\n",key_act.drvAct,key_act.key_num); //接收到按键操作动作
            opt=app_logic_act_to_opt(key_act); //将按键状态转换为操作状态
        }
        app_logic_general_handle(opt);
        vTaskDelay(pdMS_TO_TICKS(EXAMPLE_CHASE_SPEED_MS)); //延时10ms
    }
}

void task_app_logic_init()
{
    xTaskCreate(app_logic_loop,"app_logic_dazzling_loop",7168,NULL,TASK_PROP_APP,&thread_app_dazzling);
}